﻿(function ($, undefined) {

    $.fn.projectTab = function (projectInfo, currentTabId) {
        this.each(function () {
            var _self = $(this);

            var projectTabList = [
                { title: "项目团队", id: 'link-team', href: '/project/projectMembers/{id}' },
                { title: "工作任务", id: 'link-workitems', href: '/project/projectWorkitems/{id}' },
                { title: "项目计划", id: 'link-tasks', href: '/project/ProjectTasks/{id}' }
            ];

            var ulRoot = $('<ul/>');

            $(projectTabList).each(function (index, item) {
                var link = $('<a id="{id}">{title}</a>'
                            .replace('{id}', item.id)
                            .replace('{title}', item.title)
                            ).appendTo(ulRoot);

                link.addClass('tabItem');
                if (currentTabId == item.id) {
                    link.addClass('current');
                } else {
                    link.attr('href', item.href.replace('{id}', projectInfo.Id));
                }

                $('<li/>').append(link).appendTo(ulRoot);
            });

            ulRoot.appendTo(_self);
        });
    }

})(jQuery);
